import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';
import ResponseConstants from '../../common/ResponseConstants';

export default class LoginSendAction extends BaseAction {
  constructor() {
    super();

    this.moduleType = Constants.MODULE_TYPE.LOGIN;
    this.name = "LoginSendAction";
  }

  call(caller, data) {
    this._baseCall(caller, data);
    this.caller.setState({
      viewStatus: 4,
    })
  }

  // DqappUserDetail {
  //   avatar_url (string, optional): 头像 ,
  //   department (string, optional): 所属单位 ,
  //   ee_no (integer, optional): 员工编号 ,
  //   mobile (string, optional): 手机号码 ,
  //   name (string, optional): 员工名字 ,
  //   nick (string, optional): 昵称 ,
  //   perms (Array[string], optional): 权限集
  //   }
  finish(responseData, isSucceed, response) {
    var status = response.status;
    var detail = responseData.detail;
    var authorization = "0";
    if(response && response.headers.map.authorization) {
      authorization = response.headers.map.authorization[0];
    }
    if(status == ResponseConstants.status_deal_success || status == ResponseConstants.status_request_success) {
      detail = "登录成功";
    }
    this.caller.setState({
      viewStatus: status,
      statusText:detail,
      userData:responseData,
      authorization: authorization,
    })
  }
}
